/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package parismetro;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.Stack;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.effect.InnerShadow;
import javafx.scene.input.MouseEvent;
import modele.RERTicket;
import modele.RERBook;
import modele.TplusTicket;
import modele.TplusBook;

/**
 * @author Hadrien
 */
def f:Font = Font{size:48, embolden:true};

public class ButtonBook extends CustomNode {
    public-init var number:Integer;
    public var coul:Color = Color.WHITE;
    public var s: Stack = Stack {
                //effect: bind e
                content:[
                    Rectangle {
                    arcWidth: 10, arcHeight: 10
                    fill: Color.WHITE
                    height:95;
                    width:95;
                    }
                    Text {
                        font: f
                        content: "{number}"
                        fill: bind coul
                    }
                ]
                onMousePressed: function(e: MouseEvent): Void {
                    if ((Main.orderList.orders[Main.orderList.orders.size()-1] instanceof TplusBook) or (Main.orderList.orders[Main.orderList.orders.size()-1] instanceof RERBook)) {
                        Main.orderList.orders[Main.orderList.orders.size()-1].quantity = number;
                    } else{
                        if (Main.orderList.orders[Main.orderList.orders.size()-1] instanceof TplusTicket) {
                            Main.orderList.orders[Main.orderList.orders.size()-1] = TplusBook{quantity:number; reduceFare:false; orderList:Main.orderList};
                        } else if (Main.orderList.orders[Main.orderList.orders.size()-1] instanceof RERTicket) {
                            var old : RERTicket = Main.orderList.orders[Main.orderList.orders.size()-1] as RERTicket;
                            var r = RERBook {
                                reduceFare:old.reduceFare;
                                quantity: number;
                                startStation: old.startStation;
                                endStation: old.endStation;
                                orderList:Main.orderList
                            }
                            Main.orderList.orders[Main.orderList.orders.size()-1] = r;
                        }

                    }
                }

}
    public var isSelected:Boolean = bind {
        (Main.orderList.orders[Main.orderList.orders.size()-1].quantity == number) and ((Main.orderList.orders[Main.orderList.orders.size()-1] instanceof TplusBook) or (Main.orderList.orders[Main.orderList.orders.size()-1] instanceof RERBook))
    } on replace {
        if (isSelected) {
            coul = Color.BLACK;
        } else {
            coul = Color.rgb(200,200,200);
        }
        };

override public function create():Node{
    return s;
}

}
